package com.googlecode.flealancemarket.tapestry.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry.OptionGroupModel;
import org.apache.tapestry.OptionModel;
import org.apache.tapestry.util.AbstractSelectModel;

/**
 * General purpose selection model for domain classes implemented as JavaBeans
 * It needs a reference to a List containing all available instances of its type - rawList,
 * This list will be used as a source for populating the model
 * 
 * @author Goran Jovic <goranjovic@gmail.com/>
 * @since Sep 16, 2008
 **/

public class BeanSelectModel<T> extends AbstractSelectModel {
	
	private List<T> rawList;
	
	public BeanSelectModel(List<T> rawList){
		this.rawList=rawList;
	}

	public List<OptionGroupModel> getOptionGroups() {
		return null;
	}

	public List<OptionModel> getOptions() {
		List<OptionModel> refinedList = new ArrayList<OptionModel>();
		for(T bean : rawList){
			OptionModel model = new BeanOptionModel<T>(bean);
			refinedList.add(model);
		}
		return refinedList;
	}

}
